﻿// -----------------------------------------------------------------------
// <copyright file="HelperFunctions.cs" company="Hewlett-Packard">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ImageProcessing
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public static class HelperFunctions
    {
        /// <summary>
        /// Cutoffs the specified img.
        /// </summary>
        /// <param name="img">The img.</param>
        /// <returns>the cutoff image</returns>
        public static Entities.IMG_Image Cutoff(Entities.IMG_Image img)
        {
            int width = img.Width;
            int height = img.Height;
            Entities.IMG_Image image = new Entities.IMG_Image(width, height);
            double red, green, blue;
            for (int i = 0; i < width * height; i++)
            {
                red = img.ImagePixels[i].Red;
                green = img.ImagePixels[i].Green;
                blue = img.ImagePixels[i].Blue;
                red = red > 255 ? 255 : red;
                red = red < 0 ? 0 : red;

                green = green > 255 ? 255 : green;
                green = green < 0 ? 0 : green;

                blue = blue > 255 ? 255 : blue;
                blue = blue < 0 ? 0 : blue;

                image.ImagePixels[i] = new Entities.Pixel(red, green, blue);
            }

            return image;
        }
    }
}
